﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL.Entiteti;

namespace KSZ
{
    public partial class DodajEkipu : Form
    {
        string Slikica;
        public DodajEkipu()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            pictureBox1.ImageLocation = openFileDialog1.FileName;
            Slikica = openFileDialog1.FileName;
            List<char> test = new List<char>();
            int i = 0;
            while (i < Slikica.Length)
            {
                test.Add(Slikica[i]);
                if (Slikica[i] == '\\')
                {
                    test.Add('\\');
                }
                i++;
            }
            Slikica = string.Join("", test);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (t_ime_kluba.Text == "") throw new Exception("Nema imena kluba!");
                if (t_grad_kluba.Text == "") throw new Exception("Nema grada kluba!");
                if (Slikica == "") throw new Exception("Niste odabrali logo!");
                Klub NoviKlub = new Klub(t_ime_kluba.Text, t_grad_kluba.Text, Slikica);
                DAL.DAL d = DAL.DAL.Instanca;
                d.kreirajKonekciju("localhost", "mydb", "root", "FCChelsea1");
                DAL.DAL.KlubDAO cd = new DAL.DAL.KlubDAO();
                cd.create(NoviKlub);
                d.terminirajKonekciju();
                MessageBox.Show("Ekipa Uspješno Dodana!");
                this.Close();
            }
            catch (Exception gh)
            {
                MessageBox.Show(gh.Message);
            }
        }
    }
}
